<?php
/*
Template Name: Blog Page
*/
?>
<?php
$realestate_page_template_settings = array();
$realestate_page_template_settings = maybe_unserialize( get_post_meta($post->ID,'realestate_page_template_settings',true) );

$fullwidth = isset( $realestate_page_template_settings['realestate_fullwidthpage'] ) ? (bool) $realestate_page_template_settings['realestate_fullwidthpage'] : false;

$realestate_page_template_blogstyle = isset( $realestate_page_template_settings['realestate_page_template_blogstyle'] ) ? (bool) $realestate_page_template_settings['realestate_page_template_blogstyle'] : false;

$realestate_page_template_showthumb = isset( $realestate_page_template_settings['realestate_page_template_showthumb'] ) ? (bool) $realestate_page_template_settings['realestate_page_template_showthumb'] : false;

$blog_cats = isset( $realestate_page_template_settings['realestate_page_template_blogcats'] ) ? (array) $realestate_page_template_settings['realestate_page_template_blogcats'] : array();
$realestate_page_template_blog_perpage = isset( $realestate_page_template_settings['realestate_page_template_blog_perpage'] ) ? (int) $realestate_page_template_settings['realestate_page_template_blog_perpage'] : 10;
?>
<?php get_header(); ?>
	<div id="content-top">
		<div id="menu-bg"></div>
		<div id="top-index-overlay"></div>
		<div id="content" class="clearfix<?php if($fullwidth) echo(' fullwidth');?>">
			<div id="main-area">
				<?php get_template_part('includes/breadcrumbs'); ?>
				<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
				<div class="full_entry clearfix">
					<?php if (get_option('realestate_integration_single_top') <> '' && get_option('realestate_integrate_singletop_enable') == 'on') echo(get_option('realestate_integration_single_top')); ?>
					<?php $width = 159;
						  $height = 159;
						  $classtext = '';
						  $titletext = get_the_title();
						  $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
						  $thumb = $thumbnail["thumb"]; ?>
					<div class="entry_content<?php if ($thumb <> '' && get_option('realestate_thumbnails_index') == 'on') echo(' setwidth') ?>">
						<?php if($thumb <> '' && get_option('realestate_page_thumbnails') == 'on') { ?>
							<div class="small-thumb">
								<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext , $width, $height, $classtext); ?>
								<span class="overlay"></span>
							</div><!-- end .small-thumb -->
						<?php }; ?>
						<h1 class="single-title"><?php the_title(); ?></h1>
						<?php the_content(); ?>
						<?php wp_link_pages(array('before' => '<p><strong>'.esc_html__('Pages', 'RealEstate').':</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
						<div id="realestate_page_template_blog">
							<?php $cat_query = '';
							if ( !empty($blog_cats) ) $cat_query = '&cat=' . implode(",", $blog_cats);
							else echo '<!-- blog category is not selected -->'; ?>
							<?php
								$realestate_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
							?>
							<?php query_posts("showposts=$realestate_page_template_blog_perpage&paged=" . $realestate_paged . $cat_query); ?>
							<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
								<div class="realestate_page_template_blogentry clearfix">
									<h2 class="realestate_page_template_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
									<p class="realestate_page_template_blogmeta"><?php esc_html_e('Posted', 'RealEstate'); ?> <?php esc_html_e('by', 'RealEstate'); ?> <?php the_author_posts_link(); ?> <?php esc_html_e('on', 'RealEstate'); ?> <?php the_time(get_option('realestate_date_format')) ?> <?php esc_html_e('in', 'RealEstate'); ?> <?php the_category(', ') ?> | <?php comments_popup_link(esc_html__('0 comments', 'RealEstate'), esc_html__('1 comment', 'RealEstate'), '% '.esc_html__('comments', 'RealEstate')); ?></p>
									<?php $thumb = '';
									$width = 184;
									$height = 184;
									$classtext = '';
									$titletext = get_the_title();
									$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext);
									$thumb = $thumbnail["thumb"]; ?>
									<?php if ( $thumb <> '' && !$realestate_page_template_showthumb ) { ?>
										<div class="realestate_page_template_thumb alignleft">
											<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
											<a href="<?php the_permalink(); ?>"><span class="overlay"></span></a>
										</div> <!-- end .thumb -->
									<?php }; ?>
									<?php if (!$realestate_page_template_blogstyle) { ?>
										<p><?php truncate_post(550);?></p>
										<a href="<?php the_permalink(); ?>" class="readmore"><span><?php esc_html_e('read more', 'RealEstate'); ?></span></a>
									<?php } else { ?>
										<?php
											global $more;
											$more = 0;
											the_content();
										?>
									<?php } ?>
								</div> <!-- end .realestate_page_template_blogentry -->
							<?php endwhile; ?>
								<div class="page-nav clearfix">
									<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
									else { ?>
										 <?php get_template_part('includes/navigation'); ?>
									<?php } ?>
								</div><!-- end .entry -->
							<?php else : ?>
								<?php get_template_part('includes/no-results'); ?>
							<?php endif; wp_reset_query(); ?>
						</div> <!-- end #realestate_page_template_blog -->
						<?php edit_post_link(esc_html__('Edit this page', 'RealEstate')); ?>
					</div> <!-- end .entry_content -->
				</div><!-- .full_entry -->
				<?php if (get_option('realestate_show_pagescomments') == 'on') comments_template('', true); ?>
				<?php endwhile; endif; ?>
			</div> <!-- end #main-area -->
			<?php if (!$fullwidth) get_sidebar(); ?>
<?php get_footer(); ?>